package com.itheima.publisher;

import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class PublisherApplication {

    public static void main(String[] args) {
        SpringApplication.run(PublisherApplication.class);
    }

    // 消息转换器 生产者和消费者都要配置
    // 配置类里可以配置Bean，这里是为了图方便就不再新创建配置类文件了
    // Jackson2JsonMessageConverter类：实现了MessageConverter接口，使用Jackson库将消息对象转换为JSON格式，或者将JSON格式的消息转换为Java对象
    @Bean
    public MessageConverter messageConverter() {
//        return new Jackson2JsonMessageConverter();
        Jackson2JsonMessageConverter jjmc = new Jackson2JsonMessageConverter();
        jjmc.setCreateMessageIds(true); // 设置消息ID，避免重复消费
        return jjmc;
    }

}



